﻿using System;
using System.Collections.Generic;
using System.Text;

namespace oceanho.webapi.factory.httpCore
{
    /// <summary>
    /// Mime Type mapping more than go to ↓
    /// http://www.w3school.com.cn/media/media_mimeref.asp or
    /// http://www.cnblogs.com/guizhouOceanHo/p/4750574.html
    /// </summary>
    public sealed class MimeTypes
    {
        /// <summary>
        /// text/xml
        /// </summary>
        public const string Xml = "text/xml";

        /// <summary>
        /// text/css
        /// </summary>
        public const string Css = "text/css";
        /// <summary>
        /// text/html
        /// </summary>
        public const string Html = "text/html";

        /// <summary>
        /// text/plain
        /// </summary>
        public const string Text = "text/plain";

        /// <summary>
        /// application/json
        /// </summary>
        public const string Json = "application/json";

        /// <summary>
        /// application/javascript
        /// </summary>
        public const string Script = "application/javascript";

        /// <summary>
        /// image/gif
        /// </summary>
        public const string ImageGIF = "image/gif";

        /// <summary>
        /// image/bmp
        /// </summary>
        public const string ImageBMP = "image/bmp";

        /// <summary>
        /// image/png
        /// </summary>
        public const string ImagePNG = "image/png";

        /// <summary>
        /// image/jpeg
        /// </summary>
        public const string ImageJPG = "image/jpeg";

        /// <summary>
        /// application/octet-stream
        /// </summary>
        public const string DefaultStream = "application/octet-stream";
    }

    /// <summary>
    /// 文件上传默认配置信息类
    /// </summary>
    internal sealed class FileUploadDefault
    {
        // 
        // 字节/兆转换计算参考
        // https://www.baidu.com/s?wd=%E5%AD%97%E8%8A%82%20mb%E6%8D%A2%E7%AE%97
        //-------------------------------------------------------------------//
        internal const int BufferSize = 4194304;                        // 文件上传，每次写入磁盘的buffer（0.5兆）
        internal const int AllowFileCount = 10;                         // 文件上传，允许的最多上传文件个数

        internal const long AllowFileSize = 167772160;                  // 文件上传，允许的文件总最大上传大小（20兆）
        internal const long AllowSingleFileSize = 41943040;             // 文件上传，允许的单个文件最大上传文件大小（5兆）
        internal const int ReUploadItemNameMaxCount = 5;                // 文件上传，允许的最大重命名次数（紧当服务器上文件名存在时才会出现重名的情况）

        internal const bool AutoMKDir = true;                           // 文件上传，是否允许（当保存目录不存在时）自动创建文件夹目录
        internal const bool IsUseTranstion = true;                      // 文件上传，是否采用事务模式进行文件上传


        // 文件上传，允许/不允许上传的文件类型
        internal static readonly List<string> UnOrAllowTypes = new List<string> {
            "jpg","jpeg","gif","png","bmp","txt","chm"
        };

        // 文件上传，允许上传模式（单文件/多文件）
        internal static readonly FileUploadMode FileUploadModeD = FileUploadMode.Default;

        // 文件上传，传文件类型校验模式（只允许/不允许）
        internal static readonly FileUploadTypeValidMode FileUploadTypeValidModeD = FileUploadTypeValidMode.AllowType;

        // 文件上传，文件名称冲突时的解决模式（ThrowEx/AutoNewName/BakAndUpload）
        internal static readonly FileUploadExistDoOption FileUploadExistDoOptionD = FileUploadExistDoOption.AutoNewName;
    }

    /// <summary>
    /// SecurityCfg默认配置
    /// </summary>
    internal sealed class SecurityCfgDefault
    {
        internal const int BadConnectSec = 30;
        internal const int Allow_Warn_Count = 20;
        internal const int Allow_Max_Connect = 10;
        internal const int Allow_Req_Quantity = 10;
        internal const int Allow_ClearIsBadIP_Wait_Minutes = 30;
    }
}
